//
// Created by dddgzc on 2025/2/5.
//

#include "../include/PeaBullet.h"

PeaBullet::PeaBullet() {
    size.x = 64;
    size.y = 64;
    damage = 10;
    peaBreakAnimation.setAtlas(peaBreakAtlas);
    peaBreakAnimation.setInterval(50);
    peaBreakAnimation.setIsLoop(false);
    peaBreakAnimation.setOnAnimationFinishedCallback([&]() {
        canRemove = true;
    });
}

void PeaBullet::onCollide() {
    // 碰撞音效选择
    Bullet::onCollide();
}

void PeaBullet::onDraw(const Camera &camera) {
    if (valid) {
        draw(camera, pea, (int)position.x, (int)position.y);
    }else {
        peaBreakAnimation.onDraw(camera, (int)position.x, (int)position.y);
    }

    if (IS_DEBUG_MODE) {
        drawRectangle(camera, position.x, position.y, size.x, size.y, {255, 0, 0, 255});
    }
}

void PeaBullet::onUpdate(int delta) {
    Bullet::onUpdate(delta);
    position += velocity * (float)delta;
    if (!valid) {
        peaBreakAnimation.onUpdate(delta);
    }

    if (checkIfExceedsScreen()) {
        canRemove = true;
    }
}
